﻿using System;
using System.Diagnostics;
using System.Linq;
using battlenet.wow.rt.domain.objects;
using battlenet.wow.rt.sdk.data.dto;
using battlenet.wow.rt.sdk.utility;

namespace battlenet.wow.rt.sdk.objects.Mapper
{
    internal class ItemMapper : Remapper<Item>
    {
        private readonly SlotType _slot;

        public override void RegisterMappers()
        {
            Register(typeof(ItemInfo), input => Map(input as ItemInfo));
        }

        public ItemMapper(SlotType slot)
        {
            _slot = slot;
        }

        internal Item Map(ItemInfo info)
        {
            Debug.WriteLine(string.Format("Mapping {0}...", info.Name));
            var item = new Item
            {
                Slot = _slot,
                Armor = info.Armor, 
                Context = info.Context,
                Icon = info.Icon,
                Id = info.ID,
                Name = info.Name,
                ItemLevel = info.ItemLevel,
                QualityId = info.Quality,
                Stats = info.Stats.Select(i => new Statistic(i.Stat, i.Amount)).ToList(),
                TooltipParams = info.TooltipParams.Remap(new TooltipParamsMapper())
            };
            Debug.WriteLine(string.Format("Mapping {0} complete!", info.Name));
            return item;
        }
    }
}
